package com.xqls.server.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * Created by hdg on 2017/7/11.
 */
public class MyfluChannelInitializer extends
        ChannelInitializer<SocketChannel> {
    private  Integer readerIdleTimeSeconds = 200;//读操作空闲30秒
    private  Integer writerIdleTimeSeconds = 60;//写操作空闲60秒
    private   Integer allIdleTimeSeconds = 300;//读写全部空闲200秒

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        // 添加到pipeline中的handler会被串行处理(PS: 类似工业生产中的流水线)
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("idleStateHandler", new IdleStateHandler(
                readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds));
        // 使用addLast来添加自己定义的handler到pipeline中
        pipeline.addLast(new  FluCommonDecoder());
       // pipeline.addLast(new FluCommonEncoder());// 编码
        pipeline.addLast( new TcpFluServerHandler());

    }


    public Integer getReaderIdleTimeSeconds() {
        return readerIdleTimeSeconds;
    }

    public void setReaderIdleTimeSeconds(Integer readerIdleTimeSeconds) {
        this.readerIdleTimeSeconds = readerIdleTimeSeconds;
    }

    public Integer getWriterIdleTimeSeconds() {
        return writerIdleTimeSeconds;
    }

    public void setWriterIdleTimeSeconds(Integer writerIdleTimeSeconds) {
        this.writerIdleTimeSeconds = writerIdleTimeSeconds;
    }

    public Integer getAllIdleTimeSeconds() {
        return allIdleTimeSeconds;
    }

    public void setAllIdleTimeSeconds(Integer allIdleTimeSeconds) {
        this.allIdleTimeSeconds = allIdleTimeSeconds;
    }
}
